package iscript.uiFramework.components.toolbar
{
	import flash.display.DisplayObjectContainer;
	import flash.geom.Rectangle;
	import iscript.uiFramework.components.container.Box;
	import iscript.uiFramework.components.layout.HBoxLayout;
	import iscript.uiFramework.components.layout.LayoutAlign;
	import iscript.uiFramework.components.layout.LayoutMargin;
	import iscript.uiFramework.components.UIComponent;
	import iscript.uiFramework.UIFramework;
	
	public class Toolbar extends UIComponent
	{
		
		private var _leftHBox:Box
		private var _rightHBox:Box;
		private var _toolbarRect:Rectangle;
		
		public function Toolbar(preferWidth:Number = 100, preferHeight:Number = 25)
		{
			super(preferWidth,preferHeight);
		}
		
		override protected function initialize():void
		{
			_leftHBox = new Box(_preferWidth, _preferHeight);
			_leftHBox.setLayout(new HBoxLayout());
			_leftHBox.getLayout().margin = new LayoutMargin(2, 2, 2, 2);
			
			_rightHBox = new Box(_preferWidth, _preferHeight);
			_rightHBox.setLayout(new HBoxLayout());
			_rightHBox.getLayout().margin = new LayoutMargin(2, 2, 5, 2);
			_rightHBox.getLayout().hgap = 2;
			
			_leftHBox.render(this);
			_rightHBox.render(this);
			this.width = _preferWidth;
			this.height = _preferHeight;
			
			this.background = true;
			this.getBackground().begFill(UIFramework.resource.getBitmapData("GameLite.UIComponent." + this.theme + ".Toolbar.Background"));
			
			super.initialize();
		}
		
		public function addCmpLeft(cmp:UIComponent):void
		{
			_leftHBox.append(cmp);
			
			_leftHBox.getLayout().updateAlign();
		}
		
		public function addCmpRight(cmp:UIComponent):void
		{
			_rightHBox.append(cmp);
			_rightHBox.getLayout().updateAlign();
		}
		
		override public function set width(value:Number):void
		{
			_leftHBox.width = value;
			_rightHBox.width = value;
			if (IsRender)
			{
				_leftHBox.getLayout().updateAlign();
				_rightHBox.getLayout().updateAlign();
			}
			
			super.width = value;
		
		}
		
		override public function get width():Number
		{
			return _leftHBox.width;
		}
		
		override public function set height(value:Number):void
		{
			_leftHBox.height = value;
			_rightHBox.height = value;
			if (IsRender)
			{
				_leftHBox.getLayout().updateAlign();
				_rightHBox.getLayout().updateAlign();
			}
			super.height = value;
		}
		
		override public function get height():Number
		{
			return _leftHBox.height;
		}
		
		public function get LeftHBox():Box
		{
			return _leftHBox;
		}
		
		public function get RightHBox():Box
		{
			return _rightHBox;
		}
		
		override public function render(container:DisplayObjectContainer = null):void
		{
			_leftHBox.getLayout().updateAlign(LayoutAlign.VAlign_CENTER, LayoutAlign.HAlign_LEFT);
			_rightHBox.getLayout().updateAlign(LayoutAlign.VAlign_CENTER, LayoutAlign.HAlign_RIGHT);
			super.render(container);
		}
	
	}

}
